home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibLabel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  3.4 KB  |  153 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6.  
  7. /* Code for Label */
  8. /*****************************************************************************/
  9.  
  10. mib_Widget *mib_create_Label(mib_Widget *parent, char *name, char *label,
  11.         int posx, int posy, int width, int height, int mib_fill)
  12. {
  13.   mib_Widget *temp;
  14.   mib_Label *myres;
  15.   unsigned char *label_text;
  16.   Arg     args[20];
  17.   int     n;
  18.  
  19.   /* create the new widget and add it to the tree */
  20.  
  21.   temp = mib_new_mib_Widget();
  22.   if (mib_fill == WDEFAULT)
  23.     mib_add_backward(temp, parent);
  24.   else
  25.     mib_add_mib_Widget(temp, parent);
  26.  
  27.   myres = (mib_Label *)malloc(sizeof(mib_Label));
  28.  
  29.   /* initialize public resources */
  30.  
  31.   if (mib_fill == WDEFAULT)
  32.   {
  33.     temp->name = (char *)malloc(strlen(name)+1);
  34.     strcpy(temp->name,name);
  35.   }
  36.   temp->mib_class = (char *)malloc(6);
  37.   sprintf(temp->mib_class,"Label");
  38.   temp->mib_class_num = MIB_LABEL;
  39.   temp->width = width;
  40.   temp->height = height;
  41.   temp->topOffset = posy;
  42.   temp->leftOffset = posx;
  43.   temp->bottomOffset = 0;
  44.   temp->rightOffset = 0;
  45.   temp->topAttachment = 1;
  46.   temp->leftAttachment = 1;
  47.   temp->bottomAttachment = 0;
  48.   temp->rightAttachment = 0;
  49.  
  50.   temp->mib_allowresize = 1;
  51.  
  52.   /* initialize private resources */
  53.  
  54.   temp->myres = (void *)myres;
  55.  
  56.   if (mib_fill == WDEFAULT)
  57.   {
  58.     myres->label = (char *)malloc(strlen(label)+1);
  59.     strcpy(myres->label,label);
  60.   }
  61.  
  62.   /* create Xt widget */
  63.  
  64.   n = 0;
  65.  
  66.   if (mib_fill == WDEFAULT)
  67.   {
  68.     label_text = XmStringCreateLtoR(label, XmSTRING_DEFAULT_CHARSET);
  69.  
  70.     XtSetArg (args[n], XmNlabelString, label_text); n++;
  71.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  72.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  73.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  74.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  75.     XtSetArg (args[n], XmNwidth, width); n++;
  76.     XtSetArg (args[n], XmNheight, height); n++;
  77.   }
  78.  
  79.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  80.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  81.  
  82.   temp->me = XtCreateManagedWidget(name, xmLabelWidgetClass,
  83.                 temp->parent->me, args, n);
  84.  
  85.   if (mib_fill == WDEFAULT)
  86.     XmStringFree(label_text);
  87.   
  88.  
  89.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  90.   {
  91.     mib_apply_eventhandlers(temp->me, temp);
  92.   }
  93.  
  94.   return temp;
  95. }
  96.  
  97. void mib_delete_Label(mib_Widget *this)
  98. {
  99.   mib_Label *temp = (mib_Label *)this->myres;
  100.  
  101.   free(temp->label);
  102.   free(temp);
  103. }
  104.  
  105. void mib_save_Label(mib_Widget *this, FILE *fout)
  106. {
  107.   mib_Label *temp = (mib_Label *)this->myres;
  108.  
  109.   fprintf(fout,"label: \\\"%s\\\"\\n\\\n", temp->label);
  110. }
  111.  
  112. int mib_load_Label(mib_Widget *this, mib_Buffer *fin)
  113. {
  114.   mib_Label    *myres;
  115.   unsigned char *label_text;
  116.   char          res[MI_MAXSTRLEN];
  117.   char          val[MI_MAXSTRLEN];
  118.   Arg           args[5];
  119.   int           n, vallen;
  120.  
  121.   myres = (mib_Label *)this->myres;
  122.  
  123.   if (!mib_read_line(fin, res, val))
  124.     return 0;
  125.  
  126.   if (!strcmp(res,"label"))
  127.   {
  128.     vallen = strlen(val);
  129.     if (vallen < 2)
  130.       return 0;
  131.     val[vallen-1] = '\0';
  132.     myres->label = (char *)malloc(vallen-1);
  133.     sprintf(myres->label,"%s",&(val[1]));
  134.     label_text = XmStringCreateLtoR(myres->label, XmSTRING_DEFAULT_CHARSET);
  135.  
  136.     n = 0;
  137.     XtSetArg (args[n], XmNlabelString, label_text); n++;
  138.     XtSetValues(this->me, args, n);
  139.  
  140.     XmStringFree(label_text);
  141.   }
  142.   else
  143.     return 0;
  144.  
  145.   if (!mib_read_line(fin, res, val))
  146.     return 0;
  147.  
  148.   if (strcmp(res,"EndWidget"))
  149.     return 0;
  150.  
  151.   return 1;
  152. }
  153.